<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>订单列表</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <script src="__PUBLIC__/wap/js/flexible.js"></script>
    <link href="__PUBLIC__/wap/css/icons.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/wap/css/base.css" />
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/wap/css/order.css" />

</head>
<body class="order">
<div class="head">
    <a href="javascript:history.go(-1)" class="md-close back"><i class="iconfont">&#xe617</i></a>
    <h2 >订单管理</h2>
</div>
<div class="type">
    <ul class="oder_state_c">
        <li data="all" class=" all_order_n <if condition="$_GET['order_state'] eq 'all'"> on</if>"  >
        <a href="javascript:void(0);">全部</a>
        <if condition="$count"><b>{$count}</b></if>
        </li>
        <li data="0" class="nopay_order_n <if condition="$_GET['order_state'] eq '0'"> on</if>" >
        <a href="javascript:void(0);">待付款</a>
        <if condition="$count00"> <b>{$count00}</b></if>
        </li>
        <li data="1" class="pay_order_n <if condition="$_GET['order_state'] eq '1'"> on</if>" >
        <a href="javascript:void(0);">待发货</a>
        <if condition="$count10"><b>{$count10}</b></if>
        </li>
        <li data="2" class="delivered <if condition="$_GET['order_state'] eq '2'"> on</if>" >
        <a href="javascript:void(0);">待收货</a>
        <if condition="$count20"><b>{$count20}</b></if>
        </li>
        <li data="3" class="f_order_n <if condition="$_GET['order_state'] eq '3'"> on</if>" >
        <a href="javascript:void(0);">已确认</a>
        <if condition="$count30"><b>{$count30}</b></if>
        </li>
    </ul>
</div>
<div class="page">
    <ul class="more_html">
        <volist name="list" id="vo">
            <li>
                <div class="cartlist">
                    <div class="store">
                        {$vo.store_name}的店铺<span class="state">{$vo.order_state_name}</span>
                    </div>
                    <div class="user">
                        <i class="iconfont">&#xe621</i>
                        <a href="{:U('Wap/goodsorder/order_detail',array('id'=>$vo['order_id']))}"><div class="info">
                            <dl>
                                <dt>订单号：</dt>
                                <dd class="num">{$vo.order_sn}</dd>
                            </dl>
                            <dl>
                                <dt>收件人：</dt>
                                <dd>{$vo.consignee}</dd>
                            </dl>
                            <dl>
                                <dt>地址：</dt>
                                <dd>{$vo.address}</dd>
                            </dl>
                            <dl>
                                <dt>手机号：</dt>
                                <dd class="num">{$vo.mobile}</dd>
                            </dl>
                        </div></a>
                    </div>
                    <ul>
                        <volist name="vo['goods']" id="v">
                            <li  class="goods"> <a href="{:U('Wap/goodsorder/order_detail',array('id'=>$vo['order_id']))}">
                                <div class="goodsimg imgnobg">
                                    <div class="img bgcover " style=" background:url({$v.goods_image})">
                                    </div>
                                </div>
                                <div class="info">
                                    <div class="title">
                                        {$v.goods_name}
                                    </div>
                                    <div class="pay">
                                        <div class="pirce num green">
                                            ￥{$v.goods_price}
                                        </div>
                                        <div class="qty">
                                            <span class="num">{$v.goods_number}</span>件
                                            
                                        </div>
                                    </div>
									
                                </div>
                            </a>
							<if condition="$vo.order_state eq 'delivered' and $vo.is_upgrade neq 1" >
                                                <a class="after_sales service "  href="{:U('wap/goodsrefund/index',array('id'=>$v['rec_id']))}">售后</a>
                                            </if>
                                <div class="clearfix">
                                </div>
                            </li>
                        </volist>
                    </ul>
                    <div class="total">
                        <ul>
                            <li class="subtotal">共<span class="num green"> {$vo.num} </span>件商品 合计：<span class=" num green">¥{$vo.order_amount}</span></li>
                            <li class="typetotal">

                                <!--<a href="#" class="btn1 btnsF34">去付款</a>
                                    <a href="#" class="btn1 btnsF34">查看物流</a>
                                    <a href="#" class="btn2 btnsF34">确认收货</a>
                                    <a href="#" class="btn3 btnsF34">取消订单</a>-->
                                <if condition="$vo.order_state eq 'nopay'">
                                    <if condition="$vo.is_upgrade eq 1">
                                        <a class="btn1 btnsF34" href="{:U('wap/start/start_pay',array('pay_sn'=>$vo['order_sn']))}">去付款</a>
                                        <else/>
                                        <a class="btn1 btnsF34" href="{:U('wap/goodsorder/order_pay',array('pay_sn'=>$vo['order_sn']))}">去付款</a>
                                    </if>
                                    <a class="g-tui delete_order btn3 btnsF34" data-type="1"  data="{$vo.order_id}" href="javascript:void(0)">取消订单</a>
                                    <elseif condition="$vo.order_state eq 'delivered'"/>
                                        <if condition="$vo.ref_all gt 0">
                                            <a class=" btn3 btnsF34" href="{:U('wap/goodsrefund/refund_list')}">售后申请中</a>
                                        <else/>
                                        <a class=" btn1 btnsF34" href="#">查看物流</a>
                                        <a class="delivered_order btn2 btnsF34" data="{$vo.order_id}" href="javascript:void(0)">确认收货</a>
                                        </if>
                                    <elseif condition="$vo.order_state eq 'received'"/>
                                    <a href="javascript:void(0)" class="btn2 btnsF34">{$vo.order_state_name}</a>
                                    <a class="g-tui delete_order btn3 btnsF34" data-type="0"  data="{$vo.order_id}" href="javascript:void(0)">删除</a>
                                    <elseif condition="$vo.order_state eq 'finish'"/>
                                    <a href="javascript:void(0)" class="btn2 btnsF34">{$vo.order_state_name}</a>
                                    <a class="g-tui delete_order btn3 btnsF34" data-type="0"  data="{$vo.order_id}" href="javascript:void(0)">删除</a>
                                    <else/>
                                    <a href="javascript:void(0)" class='btn2 btnsF34'style="float: none;">{$vo.order_state_name}</a>
                                </if>
                            </li>
                        </ul>
                    </div>
                </div>
            </li>
        </volist>
    </ul>
    <div class="loading">
        <div class="fm-footer-copyright get_more">
            <if condition="$count gt 10 && count($list) eq 10">
                加载更多
                <else/>
                无更多数据
            </if>
        </div>
    </div>
</div>



<div style="height:50px;">
</div>

<include file="Public/footer_new" />
<script type="text/javascript" src="__PUBLIC__/wap/js/jquery.min.js"></script>
<script src="__PUBLIC__/bootstrap/vendor/jquery-validation/jquery.validate.wap.js"></script>
<script src="__PUBLIC__/js/jquery.form.js"></script>
<script type="text/javascript" src="__PUBLIC__/layer/layer.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/return-top.js"></script>

<input type="hidden" name="p" value="2" />
<input type="hidden" name="order_state" value="{$_GET['order_state']}" />
<input type="hidden" name="order" value=""/>

<script type="text/javascript">
    var load_more = 0;
    var load_none = 0;
    $(function () {

        $(window).scroll(function () {
            var scrollTop = $(this).scrollTop();
            var scrollHeight = $(document).height();
            var windowHeight = $(this).height();
            if (scrollTop + windowHeight == scrollHeight) {
                //此处是滚动条到底部时候触发的事件，在这里写要加载的数据，或者是拉动滚动条的操作
                if (load_none != 1) {
                    if (load_more == 1) {
                        var html = ' <img src="__PUBLIC__/wap/img/icon_zhuan.gif" style="max-width:15px;">'
                        $('.get_more').html('加载中' + html);
                    } else {
                        get_more();
                    }
                }

            }
        });
    })
    $(function(){
        $(".get_more").click(function(){
            get_more();
        });
        $(window).load(function () {
            get_more();
        });
        $(".oder_state_c li").click(function(){
            $('.oder_state_c li').removeClass('on');
            $(this).addClass('on');
            var data=$(this).attr('data');
            $("input[name='order_state']").val(data);
            $("input[name='p']").val(1);
            get_more();
        });
        $('.more_html').on('click','.delete_order',function(){
            var __this=$(this);
            var order_id=__this.attr('data');
            var data_type=__this.attr('data-type');
            var types="删除";
            if(data_type==1){
                types="取消";
            }
            layer.confirm('确定'+types+'该订单？', {
                btn: ['确定','取消'] //按钮
            }, function(){
                layer.msg(types+'中请稍候....', {time: 5000});
                $.ajax({
                    url: "{:U('wap/goodsorder/order_del')}",
                    type:'post',
                    data: {order_id:order_id},
                    dataType: 'json',
                    success: function(data){
                        //console.log(data);
                        if(data.status==1){
                            var str=$('.oder_state_c .all_order_n b:eq(0)').html();
                            $('.oder_state_c .all_order_n b:eq(0)').html(parseInt(str) - 1);
                            if (parseInt(str) == 1){
                                $('.oder_state_c .all_order_n b:eq(0)').css('display','none');
                            }
                            if(data.code=='nopay'){
                                var str=$('.oder_state_c .nopay_order_n b:eq(0)').html();
                                $('.oder_state_c .nopay_order_n b:eq(0)').html(parseInt(str) - 1);
                                if (parseInt(str) == 1){
                                    $('.oder_state_c .nopay_order_n b:eq(0)').css('display','none');
                                }
                            }else{
                                var str=$('.oder_state_c .f_order_n b:eq(0)').html();
                                $('.oder_state_c .f_order_n b:eq(0)').html(parseInt(str) - 1);
                                if (parseInt(str) == 1){
                                    $('.oder_state_c .f_order_n b:eq(0)').css('display','none');
                                }
                            }

                            layer.msg(types+'成功', {icon: 6,time: 1500},function(){
                                $("input[name='p']").val(1);
                                get_more();
                                ///刷新页面
                            });
                        }else{
                            layer.msg(data.error, {icon: 5});
                        }
                    }
                });
            }, function(){

            });

        });
    });
    function get_more(){
        load_more = 1;
        var html = ' <img src="__PUBLIC__/wap/img/icon_zhuan.gif" style="max-width:15px;">';
        $('.get_more').html('加载中' + html);
        var p=$("input[name='p']").val();
        var order_sta=$("input[name='order_state']").val();
        $.ajax({
            url: "{:U('wap/goodsorder/index')}",
            type:'post',
            data: {p:p,order_state:order_sta},
            dataType: 'json',
            success: function(data){
                //console.log(data);
                var con=1;
                var option='';
                if(data){
                    $.each(data, function(i, value) {

                        //this指向当前元素
                        //i表示Array当前下标
                        //value表示Array当前元素
                        var order_state="";
                        if(value.order_state=="nopay"){
                            var pay_url = "<?php echo U('wap/goodsorder/order_pay'); ?>?pay_sn="+value.order_sn;
                            if(value.is_upgrade == 1){
                                pay_url = "<?php echo U('wap/start/start_pay'); ?>?pay_sn="+value.order_sn;
                            }
                            order_state='<div class="order-button "><a  class="btn1 btnsF34" href="'+pay_url+'" >去付款</a>'
                                    +' <a class="g-tui delete_order btn3 btnsF34" data-type="1" data="'+value.order_id+'" href="javascript:void(0)">取消订单</a></div>';
                        }else if(value.order_state=="delivered"){
                            var str_delivered="";
                            if(value.is_refund>0 && value.rec_id>0){
                                if(value.ref_all>0){
                                    str_delivered='<a class=" btn3 btnsF34" href="{:U('wap/goodsrefund/refund_list')}">售后申请中</a>' ;
                                }else{
                                    str_delivered= '<a class="delivered_order btn1 btnsF34" href="#">查看物流</a>'
                                            +' <a class="delivered_order btn2 btnsF34" data="'+value.order_id+'" href="javascript:void(0)">确认收货</a>'

                                }
                            }else if(value.is_refund>0 && value.rec_id==0){
                                if(value.ref_all>0){
                                    str_delivered='<a class=" btn3 btnsF34" href="{:U('wap/goodsrefund/refund_list')}">售后申请中</a>' ;
                                }else{
                                    str_delivered='<a class="delivered_order btn1 btnsF34" href="#">查看物流</a>'
                                            +'<a class="delivered_order btn2 btnsF34" data="'+value.order_id+'" href="javascript:void(0)">确认收货</a>'
                                }
                            }else{
                                str_delivered= '<a class="delivered_order btn1 btnsF34" href="#">查看物流</a>'
                                        +'<a style="float: none;" class="delivered_order btn2 btnsF34" data="'+value.order_id
                                        +'" href="javascript:void(0)">确认收货</a>';
                            }
                            order_state='<div class="order-button">'+str_delivered+'</div>';
                        }else if(value.order_state=="received"){
                            order_state='<div class="order-button"> <a class="btn2 btnsF34" href="javascript:void(0);">'+value.order_state_name
                                    +'</a><a class="g-tui delete_order btn3 btnsF34" data-type="0" data="'+value.order_id+'" href="javascript:void(0)">删除</a></div>';
                        }else if(value.order_state=="finish"){
                            order_state='<div class="order-button "> <a class="btn2 btnsF34" href="javascript:void(0);">'+value.order_state_name
                                    +'</a><a class="g-tui delete_order btn3 btnsF34" data-type="0" data="'+value.order_id+'" href="javascript:void(0)">删除</a></div>';
                        }else{
                            order_state='<div class="order-button "><a href="javascript:void(0);" class="btn2 btnsF34" style="float: none;">'+value.order_state_name+'</a></div>';
                        }
                        var goods_list = "";
                        var goods=value.goods;
                        if(goods){
                            $.each(goods, function (n, vo) {

                                var after='';
                                if(value.order_state == 'delivered' && value.is_upgrade != '1'){
                                    after = '<a class="after_sales"  href="<?php echo U('wap/goodsrefund/index');?>?id='+vo.rec_id+'">售后</a>';
                                }
                                goods_list =goods_list+ ''
                                        +'<li  class="goods"> '
                                        + '<a class="" href="<?php echo U('wap/goodsorder/order_detail');?>?id='+value.order_id+'">'
                                +'<div class="goodsimg imgnobg">'
                                +'<div class="img bgcover " style=" background:url('+vo.goods_image+')">'
                                +'</div>'
                                +'</div>'
                                +'<div class="info">'
                                +'<div class="title">'
                                +vo.goods_name
                                +' </div>'
                                +' <div class="pay">'
                                +'<div class="pirce num green">'
                                +'￥'+vo.goods_price
                                +'</div>'
                                +'<div class="qty">'
                                +'<span class="num">'+vo.goods_number+'</span>件'
                                +after
                                +'</div>'
                                +'</div>'
                                +'</div>'
                                +'</a>'
                                +'<div class="clearfix">'
                                +'</div>'
                                +'</li>';
                            });
                        }
                        option=option+'<li>'
                                +'<div class="cartlist">'
                                +'<div class="store">'
                                +value.store_name+'的店铺<span class="state">'+value.order_state_name+'</span>'
                                +'</div>'
                                +'<div class="user">'
                                +'<i class="iconfont">&#xe621</i>'
                                +'<a href="<?php echo  U('Wap/goodsorder/order_detail');?>?id='+value.order_id+'"><div class="info">'
                        +'<dl>'
                        +'<dt>订单号：</dt>'
                        +'<dd class="num">'+value.order_sn+'</dd>'
                        +'</dl>'
                        +'<dl>'
                        +'<dt>收件人：</dt>'
                        +'<dd>'+value.consignee+'</dd>'
                        +'</dl>'
                        +'<dl>'
                        +'<dt>地址：</dt>'
                        +'<dd>'+value.address+'</dd>'
                        +'</dl>'
                        +'<dl>'
                        +'<dt>手机号：</dt>'
                        +'<dd class="num">'+value.mobile+'</dd>'
                        +'</dl>'
                        +'</div></a>'
                        +'</div>'
                        +'<ul>'+goods_list+'</ul><div class="total"><ul>'
                        +'<li class="subtotal">共<span class="num black"> '+value.num+' </span>件商品 合计：<span class=" num green">¥'+value.order_amount+'</span></li>'
                        +'<li class="typetotal">'
                        + order_state+'</li></ul></li>';
                        con++;
                    });
                }
                if(p==1){
                    $('.more_html').html(option);
                }else{
                    $('.more_html').append(option);
                }
                load_more = 0;
                if (option) {
                    $("input[name='p']").val(parseInt(p) + 1);
                }
                if(con<10){
                    load_none = 1;
                    $('.get_more').html('无更多数据');
                    $('.get_more').fadeOut('3000');
                }
            }
        });
    }

</script>
<script type="text/javascript">
    $(function(){
        //确认收货
        $('.more_html').on('click','.delivered_order',function(){
            var __this=$(this);
            var order_id=__this.attr('data');
            layer.confirm('是否确认收货？确认收货后订单不可退换！', {
                btn: ['确定','取消'] //按钮
            }, function(){
                if(order_id){
                    $.ajax({
                        url: "{:U('wap/goodsorder/order_delivered')}",
                        type:'post',
                        data: {order_id:order_id},
                        dataType: 'json',
                        success: function(data){
                            console.log(data);
                            if(data.status==1){
                                var str=$('.oder_state_c .pay_order_n b:eq(0)').html();
                                $('.oder_state_c .pay_order_n b:eq(0)').html(parseInt(str) - 1);
                                if (parseInt(str) == 1){
                                    $('.oder_state_c .pay_order_n b:eq(0)').css('display','none');
                                }
                                var str=$('.oder_state_c .f_order_n b:eq(0)').html();
                                $('.oder_state_c .f_order_n b:eq(0)').html(parseInt(str) + 1);
                                $('.oder_state_c .f_order_n b:eq(0)').css('display','show');
                                //alert("确认收货成功");
                                layer.msg('确认收货成功', {icon: 6,time: 1500},function(){
                                    $("input[name='p']").val(1);
                                    get_more();
                                    ///刷新页面
                                });
                                //$('.delivered_html').remove();
                            }else{
                                layer.msg(data.error, {icon: 5});
                                //alert(data.error)
                            }
                        }
                    });
                }else{
                    layer.msg('系统繁忙,请稍后再试', {icon: 5});
                    //alert('系统繁忙,请稍后再试')
                }

            }, function(){

            });

        });

    });
</script>
</body>
</html>